#include "UnitTest++.h"
#include "IndexGenerator.h"

TEST(ItShouldGenerateAnIndexFromADictionaryWithOneWord)
{
    //arrange
    IndexGenerator generator("test/resources/dic1.txt");
    std::stringstream index;
    std::stringstream expectedIndex;
    expectedIndex << "humans: 1 \n";

    //act
    generator.generateIndex(index, "test/resources/book1.txt");

    //assert
    CHECK_EQUAL(expectedIndex.str(), index.str());
}

TEST(ItShouldGenerateIndexFromMoreThanTwoWords)
{
    //arrange
    IndexGenerator generator("test/resources/dic2.txt");
    std::stringstream index;
    std::stringstream expectedIndex;
    expectedIndex << "human: 3 \n"
            "This approach: 1 \n"
            "more importantly: 2 \n"
            "humans solve: 1 \n";

    //act
    generator.generateIndex(index, "test/resources/book3.txt");

    //assert
    CHECK_EQUAL(expectedIndex.str(), index.str());
}

TEST(ItShouldGenerateIndexWithAnInexistentSubject)
{
    //arrange
    IndexGenerator generator("test/resources/dic3.txt");
    std::stringstream index;
    std::stringstream expectedIndex;
    expectedIndex << "human: 3 \n"
            "This approach: 1 \n";

    //act
    generator.generateIndex(index, "test/resources/book3.txt");

    //assert
    CHECK_EQUAL(expectedIndex.str(), index.str());
}

TEST(ItShouldGenerateAnEmptyIndexNoneSubjectMatch)
{
    //arrange
    IndexGenerator generator("test/resources/dic4.txt");
    std::stringstream index;
    std::stringstream expectedIndex;
    expectedIndex << "";

    //act
    generator.generateIndex(index, "test/resources/book3.txt");

    //assert
    CHECK_EQUAL(expectedIndex.str(), index.str());
}

TEST(ShouldGoToNextWordIfTheFirstCharacterDoesntMacht)
{
    //arrange
    IndexGenerator generator("test/resources/dic5.txt");
    std::stringstream index;
    std::stringstream expectedIndex;
    expectedIndex << "sol: 2 \n"
            "dado: 3 \n";

    //act
    generator.generateIndex(index, "test/resources/book4.txt");

    //assert
    CHECK_EQUAL(expectedIndex.str(), index.str());
}